Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify that time_ns is monotonic #57129

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

clarify that time_ns is monotonic #57129

wants to merge 6 commits into from

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Jan 22, 2025

Since time_ns() is based on uv_hrtime, the docs should note that it is guaranteed to be monotonic (see also #2464 and this discourse thread). This PR also notes that you can't compare times across machines or reboots, and that the timing resolution is system-dependent.

On Unix systems, it calls clock_gettime(CLOCK_MONOTONIC, &t) and the GNU libc manual notes that the reference time "may change if the system is rebooted or suspended." On Windows, it calls QueryPerformanceCounter.

(This docstring was last discussed in #54696.)

Also, I changed

The primary use is for measuring the elapsed time between two moments in time.

To "The primary use is for measuring elapsed times during program execution" (emphasis added), since you don't want to use this to compare arbitrary "moments", e.g. from different runs of a program (that may span a system reboot).

@stevengj stevengj added docs This change adds or pertains to documentation dates Dates, times, and the Dates stdlib module labels Jan 22, 2025
@stevengj
Copy link
Member Author

For reference, I also want link the discussion at w3c/hr-time#115 — it turns out that whether CLOCK_MONOTONIC ticks during sleep is system-dependent.

@PallHaraldsson
Copy link
Contributor

This should be backported to older versions, at least latest 1.10.x, not just its next minor version?! Specifically, and also pointing out, and asking about general doc policy, when it's not a new feature, but applied to the existing one, like here.

@IanButterworth IanButterworth added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 dates Dates, times, and the Dates stdlib module docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants